import os
from colorama import Fore, Style
from datetime import datetime

# Color constants for console output
G = Fore.GREEN
Y = Fore.YELLOW
R = Fore.RED
R = Style.RESET_ALL

class Logger:
    '''Custom logger class for handling application logging'''
    
    def __init__(self, classname: str) -> None:
        self.classname = classname
        # Create log file with timestamp
        self.file_path = f'./logs/{datetime.now().strftime('%H_%M_%S')}_{self.classname}.log'
        if os.path.exists(self.file_path):
            os.remove(self.file_path)
        open(self.file_path, 'x', encoding='utf-8')
        self.file_context = open(self.file_path, 'a', encoding='utf-8')
        
        # Track log counts: [info, warning, error]
        self.log_counter: list[int] = [0, 0, 0]

    def getTime(self) -> str:
        '''Get current time in HH:MM:SS format'''
        return datetime.now().strftime('%H:%M:%S')

    def logInfo(self, message: str) -> None:
        '''Log informational message'''
        print(f'{G}[{self.getTime()}][INFO/{self.classname}]:{R} {message}')
        self.file_context.write(f'[{self.getTime()}][INFO/{self.classname}]: {message}\n')
        self.log_counter[0] += 1

    def logWarning(self, message: str) -> None:
        '''Log warning message'''
        print(f'{Y}[{self.getTime()}][WARNING/{self.classname}]:{R} {message}')
        self.file_context.write(f'[{self.getTime()}][WARNING/{self.classname}]: {message}\n')
        self.log_counter[1] += 1

    def logError(self, message: str) -> None:
        '''Log error message'''
        print(f'{R}[{self.getTime()}][ERROR/{self.classname}]:{R} {message}')
        self.file_context.write(f'[{self.getTime()}][ERROR/{self.classname}]: {message}\n')
        self.log_counter[2] += 1

    def __str__(self) -> str:
        '''String representation of logger statistics'''
        return f'Logger(classname={self.classname}, logs_info={self.log_counter[0]}, logs_warning={self.log_counter[1]}, logs_error={self.log_counter[2]})'